﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QD.Snapshot.Core.BLL
{
    public class NumHelper
    {
        /// <summary>
        /// 360的截图平均速度
        /// </summary>
        public int Num360 { get; private set; }
        /// <summary>
        /// 百度的截图平均速度
        /// </summary>
        public int NumBD { get; private set; }
        /// <summary>
        /// 搜狗的截图平均速度
        /// </summary>
        public int NumSogou { get; private set; }
        /// <summary>
        /// Bing的截图平均速度
        /// </summary>
        public int NumBing { get; private set; }
        /// <summary>
        /// 中国搜索的截图平均速度
        /// </summary>
        public int NumGuoSou { get; set; }
        /// <summary>
        /// 微信搜狗的截图平均速度
        /// </summary>
        public int NumWeixin { get; set; }
        /// <summary>
        /// 微信搜狗的截图平均速度
        /// </summary>
        public int NumShenMa{ get; set; }

        /// <summary>
        /// 等待的时间
        /// </summary>
        public int maxSeccend { get { return 20; } }

        static int _num360 = 0;
        static DateTime time360 = DateTime.Now;
        public void SetNum360(int num)
        {
            if (DateTime.Now.Subtract(time360).TotalSeconds > maxSeccend)
            {
                Num360 = _num360;
                _num360 = 0;
                time360 = DateTime.Now;
            }
            _num360 += num;
        }

        static int _numBD = 0;
        static DateTime timeBD = DateTime.Now;
        public void SetNumBD(int num)
        {
            if (DateTime.Now.Subtract(timeBD).TotalSeconds > maxSeccend)
            {
                NumBD = _numBD;
                _numBD = 0;
                timeBD = DateTime.Now;
            }
            _numBD += num;
        }

        static int _numSoGou = 0;
        static DateTime timeSoGou = DateTime.Now;
        public void SetNumSoGou(int num)
        {
            if (DateTime.Now.Subtract(timeSoGou).TotalSeconds > maxSeccend)
            {
                NumSogou = _numSoGou;
                _numSoGou = 0;
                timeSoGou = DateTime.Now;
            }
            _numSoGou += num;
        }

        static int _numWeixin = 0;
        static DateTime timeWeixin = DateTime.Now;
        public void SetNumWeixin(int num)
        {
            if (DateTime.Now.Subtract(timeWeixin).TotalSeconds > maxSeccend)
            {
                NumWeixin = _numWeixin;
                _numWeixin = 0;
                timeWeixin = DateTime.Now;
            }
            _numWeixin += num;
        }


        static int _numBing = 0;
        static DateTime timeBing = DateTime.Now;
        public void SetNumBing(int num)
        {
            if (DateTime.Now.Subtract(timeBing).TotalSeconds > maxSeccend)
            {
                NumBing = _numBing;
                _numBing = 0;
                timeBing = DateTime.Now;
            }
            _numBing += num;
        }


        static int _numGuoSou = 0;
        static DateTime timeGuoSou = DateTime.Now;
        public void SetNumGuoSou(int num)
        {
            if (DateTime.Now.Subtract(timeGuoSou).TotalSeconds > maxSeccend)
            {
                NumGuoSou = _numGuoSou;
                _numGuoSou = 0;
                timeGuoSou = DateTime.Now;
            }
            _numGuoSou += num;
        }

        static int _numShenMa= 0;
        static DateTime timeShenMa = DateTime.Now;
        public void SetNumShenMa(int num)
        {
            if (DateTime.Now.Subtract(timeShenMa).TotalSeconds > maxSeccend)
            {
                NumShenMa = _numBing;
                _numShenMa = 0;
                timeShenMa = DateTime.Now;
            }
            _numShenMa += num;
        }


        static object lockObj = new object();
        static NumHelper _instance;
        public static NumHelper Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (lockObj)
                    {
                        _instance = new NumHelper();
                    }
                }
                return _instance;
            }
        }
    }
}